//
//  XHSettingViewController.m
//  xinhua_sx
//
//  Created by 党阳阳 on 14-7-16.
//  Copyright (c) 2014年 dangyangyang. All rights reserved.
//

#import "XHSettingViewController.h"

@implementation XHSettingViewController
-(void)viewDidLoad
{
    UITableView* ta = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, 320, self.view.frame.size.height-80)];
    ta.dataSource = self;
    ta.delegate = self;
    [self setExtraCellLineHidden:ta];
    [self.view addSubview:ta];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"1"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"1"];
    }
    
    if (indexPath.row == 0)
    {
        cell.textLabel.text = @"清除缓存";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else if (indexPath.row == 1)
    {
        cell.textLabel.text = @"注销登录";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
    }
    return cell;
}
- (void)setExtraCellLineHidden: (UITableView *)tableView{
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [tableView setTableHeaderView:view];
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //if ()
    if (indexPath.row == 0)
    {
        UIAlertView* v1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"清除成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [v1 show];
    }
    else if (indexPath.row == 1)
    {   NSString* uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"UID"];
        if (!uid)
        {
            UIAlertView* v1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有登录,是否登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
            v1.tag = 100087;
            [v1 show];
            return;
        }
        UIAlertView* v1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否注销" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
        v1.tag = 10086;
        [v1 show];
    }
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 10086)
    {
        if (buttonIndex == 1)
        {
           
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"UID"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"Logout" object:nil];
            butoncl* al = [[butoncl alloc] init];
            [al postString:@"016"fff:@""];
                  }
    }
    else if (alertView.tag == 100087)
    {
        if (buttonIndex == 1)
        {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"Logout2" object:nil];

        }
    }
}
@end
